
package com.shangsi.controller;

import com.shangsi.feignservice.fallback.PaymentFeignService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author dzd
 * @date 2021-12-16
 */
@RestController
public class OrderController {

    @Resource
    private RestTemplate restTemplate;

    @Value("${service-url.nacos-user-service}")
    private String serverUrl;

    @Resource
    private PaymentFeignService paymentFeignService;

    @RequestMapping("consumer/payment/{id}")
    public String order(@PathVariable("id") Integer id){
        return restTemplate.getForObject(serverUrl+"/payment/"+id,String.class);
    }


    /**
     * 此请求需要走网关
     * @param id
     * @param year
     * @return
     */
    @RequestMapping("consumer/orderFeign/payment/{id}")
    public String orderFeign(@PathVariable("id") Integer id, @RequestHeader("year")String year){
        System.out.println("openfeign header :"+year);
        return paymentFeignService.getPayment(id);
    }


}
